package sv.gob.mh.dgii.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.springframework.security.core.GrantedAuthority;

@Entity
@Table(name = "AS_ROLES", schema = "SIIT")
public class AsRol implements Serializable, GrantedAuthority {

    private static final long serialVersionUID = -15048796312L;
    @Id
    @SequenceGenerator(name = "SEQ_AS_ROLES", sequenceName = "SEQ_AS_ROLES", allocationSize = 1, initialValue = 1)
    @Column(name = "C_ROL", unique = true, nullable = false, insertable = true, precision = 18, scale = 0)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_AS_ROLES")
    private Long crol;
    @Column(name = "S_ROL", nullable = false, length = 50)
    private String srol;
    @Column(name = "D_ROL", nullable = false, length = 100)
    private String drol;
    @Column(name = "B_ACTIVO", nullable = false, length = 1)
    private Boolean bactivo;
    @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @JoinTable(name = "AS_ROL_OPCION", joinColumns = {
        @JoinColumn(name = "C_ROL")}, inverseJoinColumns = {
        @JoinColumn(name = "C_OPCION")})
    private Set<AsOpcion> opciones = new HashSet<AsOpcion>(0);

    public AsRol() {
    }

    public AsRol(Long crol, String srol, String drol, Boolean bactivo) {
        this.crol = crol;
        this.srol = srol;
        this.drol = drol;
        this.bactivo = bactivo;
    }

    public Long getCrol() {
        return crol;
    }

    public void setCrol(Long crol) {
        this.crol = crol;
    }

    public String getSrol() {
        return srol;
    }

    public void setSrol(String srol) {
        this.srol = srol;
    }

    public String getDrol() {
        return drol;
    }

    public void setDrol(String drol) {
        this.drol = drol;
    }

    public Boolean getBactivo() {
        return bactivo;
    }

    public void setBactivo(Boolean bactivo) {
        this.bactivo = bactivo;
    }

    public Set<AsOpcion> getOpciones() {
        return opciones;
    }

    public void setOpciones(Set<AsOpcion> opciones) {
        this.opciones = opciones;
    }

	@Override
	public String toString() {
		return "AsRol [crol=" + crol + ", srol=" + srol + "]";
	}

	@Override
	public String getAuthority() {		
		return srol;
	}
    
    
}
